<template>
  <div class="home">
    <div @click="onPlus">+</div>
    <div>{{count}}</div>
    <div @click="onMinus">-</div>
    <div v-for="(item,index) in items"
    :key="index"
    @click="onClick(index)">{{item.title}}</div>
  </div>
</template>

<script>
// @ is an alias to /src


export default {
  name: 'Home',
  components: {
    
  },
  data(){
    return{
      items:[{title:"代付款",handle:function(){
        window.console.log("11111")
      }},
      {title:"代发货",handle:function(){
        window.console.log("2222")
      }},
      {title:"代收货",handle:function(){
        window.console.log("33333")
      }},
      {title:"代评价 ",handle:function(){
        window.console.log("444444")
      }}]
    }
  },
  computed:{
    count(){
      return this.$store.state.count
    }
  },
  methods:{
    onPlus(){
      // this.count++
      this.$store.dispatch("plus")
    },
    onMinus(){
      // if(this.count === 0){
      //   return
      // }

      // this.count--;
      this.$store.dispatch("minus")
    },
    onClick(index){
      var currentItem = this.items[index];
      if(typeof(currentItem.handle) === "function"){
        currentItem.handle()
      }else{
        //默认的处理
      }
    }
  }
}
</script>
